1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import UIKit
class ExampleAlertView: UIView {
@IBOutlet weak var wechatPayButton: UIButton!
@IBOutlet weak var alipayButton: UIButton!
@IBOutlet weak var amountTextField: UITextField!
@IBOutlet weak var infoLabel: UILabel!
private var shadowBtn: UIButton!
let ApplicationDelegate = (UIApplication.sharedApplication().delegate as! AppDelegate)
private var showView: UIView {
return ApplicationDelegate.window!
}
private var confirmClosure: (() -> ())?
private var cancelClosure: (() -> ())?
@objc private func shadowBtnClick() {
UIView.animateWithDuration(0.15, animations: {
self.shadowBtn.alpha = 0
self.alpha = 0
}) { (success) in
self.shadowBtn.removeFromSuperview()
self.removeFromSuperview()
}
}
class func exampleAlertView(initialMoney: String, canInput: Bool, confirmClosure:(()->()), cancelClosure: (() -> ())) -> DXPayAlertView {
let alert = NSBundle.mainBundle().loadNibNamed("ExampleAlertView", owner: nil, options: nil).first as! ExampleAlertView
alert.confirmClosure = confirmClosure
alert.cancelClosure = cancelClosure
return alert
}
override func awakeFromNib() {
self.layer.cornerRadius = 10
self.layer.masksToBounds = true
self.shadowBtn = UIButton(frame: UIScreen.mainScreen().bounds)
self.shadowBtn.addTarget(self, action: #selector(ExampleAlertView.shadowBtnClick), forControlEvents: .TouchUpInside)
self.shadowBtn.backgroundColor = UIColor.blackColor()
shadowBtn.alpha = 0.4
UIApplication.sharedApplication().keyWindow?.addSubview(shadowBtn)
}
func show() {
let size = UIScreen.mainScreen().bounds.size
self.shadowBtn.center = CGPoint(x: size.width/2, y: size.height/2)
self.center = self.shadowBtn.center
self.shadowBtn.frame = self.showView.bounds
self.shadowBtn.alpha = 0
self.alpha = 0
self.transform = CGAffineTransformMakeScale(1.2, 1.2)
UIView.animateWithDuration(0.25) {
self.shadowBtn.alpha = 0.4
self.showView.addSubview(self.shadowBtn)
UIView.animateWithDuration(0.25, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 0.1, options: .CurveEaseInOut, animations: {
self.showView.addSubview(self)
self.transform = CGAffineTransformMakeScale(1.0, 1.0)
self.alpha = 1
}, completion: { (_) in
self.transform = CGAffineTransformMakeScale(1.0, 1.0)
self.showView.addSubview(self)
self.alpha = 1
})
}
}
@IBAction func confirmBtnClick(sender: UIButton) {
self.confirmClosure?()
shadowBtnClick()
}
@IBAction func cancelBtnClick(sender: UIButton) {
self.cancelClosure?()
shadowBtnClick()
}
}
Prev Next